﻿using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Wasion.HHU.Data.Models;
using Wasion.HHU.Data.Repositories;
using SQLite.Net;
using System;
using System.Linq.Expressions;

namespace Wasion.HHU.Data.Repositories
{
    public class VObAttrMthDbRepository : BaseDbRepository
    {
        public VObAttrMthDbRepository() : base()
        {

        }
        public VObAttrMthDbRepository(SQLiteConnection connection)
            : base(connection)
        {
        }

        public Task<List<VObAttrMth>> GetAllList()
        {
            List<VObAttrMth> VObjectss;

            lock (databaseLock)
            {
                VObjectss = DbConnection.Table<VObAttrMth>().
                    ToList();
            }
            return Task.FromResult(VObjectss);
        }

        public Task<List<VObAttrMth>> GetList(Expression<Func<VObAttrMth, bool>> filter)
        {
            List<VObAttrMth> VObjectss;

            lock (databaseLock)
            {
                VObjectss = DbConnection.Table<VObAttrMth>().
                    Where(filter).
                    ToList();
            }
            return Task.FromResult(VObjectss);
        }

        public void Insert(VObAttrMth vObjects)
        {
            lock (databaseLock)
            {
                DbConnection.CreateTable<VObAttrMth>();
                DbConnection.Insert(vObjects);
            }
        }

        public void Update(VObAttrMth vObjects)
        {
            lock (databaseLock)
            {
                DbConnection.Update(vObjects);
            }
        }

        public VObAttrMth Find(object primaryKey)
        {
            VObAttrMth vObjects;

            lock (databaseLock)
            {
                vObjects = DbConnection.Find<VObAttrMth>(primaryKey);
            }
            return vObjects;
        }

        public void Delete(object primaryKey)
        {
            lock (databaseLock)
            {
                DbConnection.Delete<VObAttrMth>(primaryKey);
            }
        }

        //public void GetDefValueAttrPar()
        //{
        //    lock (databaseLock)
        //    {
        //        DbConnection.
        //    }
        //}
    }
}
